from rest_framework.generics import ListAPIView
from .serializers import CourseCategorySerializer, CourseSerializer, CourseRetrieveSerializer
from . import models
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import OrderingFilter
from .paginations import CourseListPagination
from rest_framework.generics import RetrieveAPIView


class CourseCategoryListAPIView(ListAPIView):
    """课程分类"""
    queryset = models.CourseCategory.objects.filter(is_show=True, is_delete=False).order_by('orders', '-id')
    serializer_class = CourseCategorySerializer


class CourseListAPIView(ListAPIView):
    """课程列表"""
    queryset = models.Course.objects.filter(is_show=True, is_delete=False).order_by('orders', '-id')
    serializer_class = CourseSerializer
    filter_backends = [DjangoFilterBackend, OrderingFilter]
    filter_fields = ["course_category"]
    ordering_fields = ["id", "students", "price"]
    pagination_class = CourseListPagination


class CourseRetrieveAPIView(RetrieveAPIView):
    """课程详情接口"""
    queryset = models.Course.objects.filter(is_show=True, is_delete=False)
    serializer_class = CourseRetrieveSerializer


from .serializers import CourseChapterModelSerializer


class ChapterListAPIView(ListAPIView):
    queryset = models.CourseChapter.objects.filter(is_show=True, is_delete=False).order_by('chapter')
    serializer_class = CourseChapterModelSerializer
    filter_backends = [DjangoFilterBackend]
    filter_fields = ["course"]